package com.lys.job;


import com.lys.service.DataClient;
import com.lys.service.WeatherDataCollectionService;
import com.lys.vo.City;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;
import java.util.List;

/**
 * 天气数据同步定时任务
 *
 */
public class WeatherDataSycJob extends QuartzJobBean {
    private final static Logger logger= LoggerFactory.getLogger(WeatherDataSycJob.class);

    @Autowired
    private WeatherDataCollectionService weatherDataCollectionService;
    @Autowired
    private DataClient dataClient;
    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        logger.info("天气数据同步定时任务开始");

        List<City> cityList=null;
        try {
            cityList=dataClient.cityList();
        } catch (Exception e) {
            logger.error("Exception",e);
        }
        for (City city:cityList) {
            String cityId=city.getCityId();
            logger.info("cityId:"+cityId);
            weatherDataCollectionService.syncDataByCityId(cityId);
        }
        logger.info("天气数据同步定时任务结束");
    }
}
